<template>
    <div class='listComplex' v-loading="loading">
        <div v-if="isDevOps=='Y'" class="list_dev">
            <common-list-complex style="flex:1"   @loadDatad="loadDatad" @loadDataMaind="loadDataMaind" :isApp="isApp" ref="commonList"  v-if="showList" :isTitle="isTitle" :sKey="sKey" :sKey2="sKey2" :model="model" :sOtherKey="sOtherKey" :row="row"  :company="company" :appid="appid" :listname="listname" :model_key="key" @rowDbClick="rowDbClick"></common-list-complex >
            <list-dev style="flex:1;overflow:hidden;" :company="company" :filepath="filepath"  :filepath2="filepath2" :filepath3="filepath3" :isDevOps="isDevOps" v-if="isDevOpsShow=='Y'" @loadData="devLoadData"></list-dev>  
        </div>
        <template v-else>
            <common-list-complex  @loadDatad="loadDatad" @loadDataMaind="loadDataMaind"  :isApp="isApp" ref="commonList"  v-if="showList" :isTitle="isTitle" :sKey="sKey" :sKey2="sKey2" :model="model" :sOtherKey="sOtherKey" :row="row"  :company="company" :appid="appid" :listname="listname" :model_key="key" @rowDbClick="rowDbClick"></common-list-complex >
      
        </template>
         <el-dialog
                v-el-drag-dialog
                :title="commonEditData.title"
                :modal="false"
                class="dialogClass dialog-vertical"
                style='left:0;top:0'
                center
                :visible.sync="dialogVisible3"
                >
                <list :commonListData="commonListData" ref="commonListNotice" v-if="dialogVisible3&&isList=='Y'"   @openWin="openWin2" isSearch="Y"></list>
               
                <common-edit :commonEditData="commonEditData"   @openWin="openWin2" @closeWin="closeWins" @goSearch="goSearch" v-else-if="dialogVisible3"></common-edit>
                
            </el-dialog>
    </div>
</template>
<script>
import commonListComplex  from '../components/list/commonListComplex.vue'
import CommonEdit  from './CommonEdit.vue'
import List  from './List.vue'
import ListDev  from '../components/dev/listDev.vue'
export default {
    components: {
       commonListComplex,
       CommonEdit,
       List,
       ListDev
    },
    data(){
        return{
            isDevOps:"",
            isDevOpsShow:"",
            filepaths:"",
            filepath:"",
            filepath2:"",
            filepath3:"",
            commonEditData:{
                fieldPath:"",
                filename2:"",
                sId:"",
                param_key:"",
                appid:"",
                title:""
            },
            commonListData:{
                title:"",
                appid:"",
                key:"",
                model:"",
                width:"80%",
                height:"height:60VH",
                left:"0%",
                top:"0%"
            },
            dialogVisible3:false,
            sKey:'',
            sKey2:'',
            sOtherKey:'',
            row:'',
            loading:true,
            showList:false,
            company:'',
            appid:'',
            listname:"",
            model:"",
            dbModelkey:"",
            key:'',
            isApp:"",
            isTitle:"",
            isList:""
        }
    },
    created(){
        if(sessionStorage.getItem("isDevOps")=="Y"){
            this.isDevOps="Y"
        }
        
        let sef=this;
         window.addEventListener('message', function(messageEvent) {
           sef.goSearch();
       
        },false);

        if(this.$route.query.sKey){
            this.sKey=this.$route.query.sKey;
        }
        if(this.$route.query.sKey2){
            this.sKey2=this.$route.query.sKey2;
        }
        if(this.$route.query.sOtherKey){
            this.sOtherKey=this.$route.query.sOtherKey;
        }
        if(this.$route.query.company){
            this.company=this.$route.query.company;
        }
        if(this.$route.query.row){
            this.row=Number(this.$route.query.row);
        }
        if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }
         if(this.$route.query.listname){
            this.listname=this.$route.query.listname;
        }
       if(this.$route.query.dbModelkey){
            this.dbModelkey=this.$route.query.dbModelkey;
        }
         if(this.$route.query.key){
            this.key=this.$route.query.key;
        }
        if(this.$route.query.model){
            this.model=this.$route.query.model;
        }
         if(this.$route.query.isApp){
            this.isApp=this.$route.query.isApp;
        }
         
         this.loading=false;
         this.showList=true;
        
        
    },
    methods:{
        devLoadData(data){
            
            this.$refs.commonList.loadData("Y");
        },
        loadDatad(data){
           // this.filepaths=this.filepaths=="" ? data:this.filepaths+","+data;
            if(!this.filepath){
                this.filepath=data;
            }else if(!this.filepath2){
                
                this.filepath2=data;
            }
            if(sessionStorage.getItem("isDevOps")=="Y"&&this.filepath&&this.filepath2)
                this.isDevOpsShow="Y"
        },
        loadDataMaind(data){
            this.filepath3=data;
        },
        openWin(data){
             console.log(data,"datas==============")
            // parent.postMessage(data,'*');
             if(this.isApp!="Y"){
               
                 let datas=JSON.parse(data);
                let wb_msg=datas.wb_msg;
                
                console.log(datas)
                this.$emit("openWin",data)
            }else{
                let item=JSON.parse(data);
                if(item.url.indexOf("/list")!=-1){
                    this.isList="Y";
                    let modelKey=item.modelKey;
                    let model=item.model;
                    this.commonListData.key=modelKey;
                    this.commonListData.model=model;
                }else{
                    this.commonEditData={
                        fieldPath:"",
                        filename2:"",
                        sId:"",
                        param_key:"",
                        appid:"",
                        title:"",
                        paramVals:''
                    };
                    this.commonEditData.fieldPath=item.fieldPath;
                    this.commonEditData.filename2=item.filename2;
                    this.commonEditData.appid=item.appid;
                    this.commonEditData.param_key=item.param_key;
                    this.commonEditData.title=item.buttonName;
                    this.commonEditData.paramVals=item.paramVals;
                    this.commonEditData.sId=item.sId;
                }
                this.dialogVisible3=true;
            
               
                let els=document.getElementsByClassName("el-dialog");
                for(let i=0;i<els.length;i++){
                    els[i].style.left="0";
                    els[i].style.top="0"
                }
            }
            

        },
         closeWins(datas){
            this.dialogVisible3=false;
        },
        goSearch(){
            this.$refs.commonList.goSearch();
        },
        getScrollTop(){
            return this.$refs.commonList.getScrollTop();
        },
        setScrollTop(top){
            this.$refs.commonList.setScrollTop(top);
        },
        initData(){
            this.$refs.commonList.initData();
        },
        rowDbClick(data){
           
            let rows=JSON.parse(data);
            
            let models=this.dbModelkey.split("|");//在左边菜单项里获取的
            let model=models.length>1 ? models[1]:"";//代表路由在哪个文件夹下面
            if(rows.dbModelkey){
                
                this.$post("api","api/view/getDbUrl",{key:escape(rows.dbModelkey+"|"+model),model:escape(this.model)}).then(data=>{
                    let name=data.name;
                    let sId=rows[data.fieldKey];
                    let url=data.url;
                    let field=data.field;
                    let filename=data.filename;
                    let param="sId="+sId+"&appid="+this.appid+"&filename2="+filename+"&fieldPath="+field;
                    url=url.indexOf("?")==-1 ? url+"?"+param:url+"&"+param;
                    let item={};
                    item.buttonName=name;
                    item.url=url;
                    
                    item.sId=sId;
                    item.appid=this.appid;
                    item.filename2=filename;
                    item.fieldPath=field;
                    item.paramVals=data.paramVals;

                    console.log("rowDbClick==========================================");
                    console.log(item);
                    this.openWin(JSON.stringify(item))
                })
            }
        }
    }
}
</script> 
<style scoped>
    .listComplex{
        height:100%;
        width:100%;
        overflow:hidden;
    } 
    .list_dev{
        height:100%;
        width:100%;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        padding:0;
        padding-top:0;
        display:flex;
        flex-direction:row;
    }
     .dialogClass{
        display:flex;
        flex-direction: column;
        overflow: hidden;
    }
    .dialogClass>>>.el-dialog{
        width:100%;
        flex:1;
        overflow:hidden;
        position:absolute !important;
        /*flex:1;
        overflow: hidden;*/
        height:100%;
        display:flex;
    }
    .dialogClass>>>.el-dialog__body{
        overflow:hidden !important;
    }
    
</style>